package bolita_con__nodos;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;

import bolita_con__nodos.Nodo.nodo;

public class Principal extends JPanel{
JFrame v;
	int tam;
	
	
	public Principal() {
		tam=480;
		v=new JFrame("con nodos");
		v.setSize(tam,tam);
		v.setVisible(true);
		v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		
		
	}

	public static void main(String[] args) {
		Principal n = new Principal();
		crearnodos(3);
		while (true){
			n.moverBolita();
			n.repaint();
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}

	}

	private void moverBolita() {
		nodo aux ;
		Nodo a=new Nodo();
		aux=a.tope;
		
		 while (aux!=null) {
				if (aux.pox >  this.getWidth() - aux.diam )
					aux.vx=aux.vx*-1;	

						
				if (aux.pox<0)			
					aux.vx=aux.vx*-1;		

					
						
				if (aux.poy > this.getHeight()- aux.diam)			
					aux.vy=aux.vy*-1;

						
				if (aux.vy<0)			
					aux.vy=aux.vy*-1;
	
				aux.pox+=aux.vx;		
				aux.vy+=aux.vy; 
				 aux=aux.siguiente;
		 }
	}

	private static void crearnodos(int n) {
		Nodo nn=new Nodo();
		
		for(int i=0;i<n;i++){
			nn.crear();		
	}
	}
public void paint(Graphics g){		
		super.paint(g);
		
		nodo aux ;
		Nodo a=new Nodo();
		aux=a.tope;
		
		 while (aux!=null) {
			 aux.grafico=(Graphics2D)g;
			 aux.grafico.setColor(Color.blue);			
			 aux.grafico.fillOval(aux.pox,aux.poy,aux.diam,aux.diam);	
				 aux=aux.siguiente;	
		 }
		
			
		}

}
